#include<stdio.h>
#include<time.h>
#include<stdlib.h>

//打印数组
void Print_arr(int arr[],int len)
{
    for (int i = 0; i < len; i++)
    {
        printf("arr[%d]=%d\n", i, arr[i]);
    }
    
}

//冒泡排序
void Bubule_sort(int arr[],int len)
{
    int temp;
    for (int i = 0; i < len - 1; i++)
    {
        int flag = 0;
        for (int j = 0; j < len - 1 - i; j++)
        {
            if (arr[j]>arr[j+1])
            {
                temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
                flag = 1;
            }
        }
        if (flag == 0)
        {
            return;
        }
    }
    
}


int main(int argc, char const *argv[])
{
    int arr[10] = {0};
    int len = sizeof(arr) / sizeof(int);
    srand(time(NULL));
    for (int i = 0; i < len; i++)
    {
        arr[i] = rand() % 100 + 1;
    }
    printf("冒泡排序为:\n");
    Bubule_sort(arr, len);
    Print_arr(arr, len);
    return 0;
}
